#include <allegro5\allegro.h>
#include <allegro5\allegro_font.h>
#include <allegro5\allegro_ttf.h>
#include <allegro5\allegro_native_dialog.h>
#include <allegro5\allegro_primitives.h>
#include <allegro5\allegro_image.h>
#include <allegro5\allegro_audio.h>
#include <iostream>
#include <allegro5\allegro_acodec.h>
#include "sw_game_manager.h"
#include "sw_sound_manager.h"
#include "sw_input_manager.h"
#include "sw_game_state_master.h"
#include <Box2D\Box2D.h>
#include <Box2D\Dynamics\b2World.h>
#include "globals.h"
using namespace std;

void sw_init_allegro_addons() {
	
	// init allegro stuff
	bool b = al_init();
	al_init_primitives_addon();
	al_init_image_addon();
	al_install_keyboard();
	al_install_mouse();
	al_init_font_addon();
	al_init_ttf_addon();
	
	al_install_audio();
	al_init_acodec_addon();
	al_reserve_samples(3);

}

int main(void) {

	sw_init_allegro_addons();
	
	global_screen_width = 840;
	global_screen_height = 600;
	global_frames_per_second = 60;
	global_pixel_width = 0.05;
	global_pixel_height = 0.05;

	global_input_manager = new sw_input_manager();
	global_game_state = new sw_game_state_master();
	global_game_manager = new sw_game_manager();
	global_sound_manager = new sw_sound_manager();

	// init sounds
	global_sound_manager->set_sound(sw_sound_manager::SW_SOUND_BGM, "song.ogg");
	global_sound_manager->set_sound(sw_sound_manager::SW_SOUND_ENEMY_DEATH, "EnemyDeath.ogg");
	global_sound_manager->set_sound(sw_sound_manager::SW_SOUND_MAIN_JUMP, "jump.ogg");
	
	global_screen_display = al_create_display(global_screen_width, global_screen_height);

	global_life = 100;
	global_life_factor = 0.1;

	return global_game_manager->play_game();

	//b2Vec2 gravity(0.0f, -10.0f);
	//bool doSleep = true;
	//b2World world(gravity);
	//b2BodyDef groundBodyDef;
	//groundBodyDef.position.Set(0.0f, -10.0f);
	//b2Body* groundBody = world.CreateBody(&groundBodyDef);
	//b2PolygonShape groundBox;
	//groundBox.SetAsBox(50.0f, 10.0f);
	//groundBody->CreateFixture(&groundBox, 0.0f);
	//b2BodyDef bodyDef;
	//bodyDef.type = b2_dynamicBody;
	//bodyDef.position.Set(0.0f, 4.0f);
	//b2Body* body = world.CreateBody(&bodyDef);
	//b2PolygonShape dynamicBox;
	//dynamicBox.SetAsBox(1.0f, 1.0f);
	//b2FixtureDef fixtureDef;
	//fixtureDef.shape = &dynamicBox;
	//fixtureDef.density = 1.0f;
	//fixtureDef.friction = 0.3f;
	//body->CreateFixture(&fixtureDef);
	//float32 timeStep = 1.0f / 60.0f;
	//int32 velocityIterations = 8;
	//int32 positionIterations = 3;
	//for (int32 i = 0; i < 60; ++i)
	//{
	//	world.Step(timeStep, velocityIterations, positionIterations);
	//	b2Vec2 position = body->GetPosition();
	//	float32 angle = body->GetAngle();
	//	printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);
	//}
	//int i;
	//cin >> i;
}